<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
set_html('title','我的订单');
if($_RQ['op']=='main'){
	$type=intval($_RQ['type'])==9?9:0;
	$return['setting']=$this->plugin_setting('page');
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$return['params']['type']=$type;
	$return['commission_money']=$this->sum('commission',$params,'money');
	$return['commission_total']=$this->count('commission',$params);
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$lastdaytime = $daytime-24*3600;
	$types=array(0,1,2,3,4,5,6,7,8);
	$return['ordernum0']=$this->count('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$return['totalday0']=$this->sum('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$daytime),'money');
	$return['totallastday0']=$this->sum('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime between'=>array($lastdaytime,$daytime)),'money');
	$return['commission_total0']=$this->sum('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$types=9;
	$return['ordernum9']=$this->count('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$return['totalday9']=$this->sum('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$daytime),'money');
	$return['totallastday9']=$this->sum('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime between'=>array($lastdaytime,$daytime)),'money');
	$return['commission_total9']=$this->sum('commission',array('type'=>$types,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'money');
	$return['list']=array();
	$return['psize']=20;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid']);
	$level=intval($_RQ['level']);
	if(!$level){
		$level=1;
	}
	//$params['level']=$level;
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,1,2,3,4,5,6,7,8);
		$return['params']['type']=$_RQ['type'];
		//$params['type']=$_RQ['type'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$order=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>$item['ordersn']));
		$item['member']=model('core/member')->basic($order['mid']);
		$item['goodsid']=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$order['id']),'goodsid');
		$item['goodstitle']=pdo_getcolumn('jy_weishop_goods',array('id'=>$item['goodsid']),'title');
		$item['type']=$this->fee_types[$item['type']];
		$item['statustitle']=$this->commission_status[$item['status']];
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		if($item['type']==2 && $item['status']==0){
			$this->update('commission',array('status'=>1),array('id'=>$item['id']));
		}
	}
	//exi('num'.count($list),'error');
	exi($list);
}
?>